//
//  DrawUtil.m
//  IOSUtil
//
//  Created by  on 11-11-21.
//  Copyright (c) 2011年 __MyCompanyName__. All rights reserved.
//

#import "ZBDrawUtil.h"


CGPathRef CGPathCreateRoundrect(CGRect rect, CGFloat radius)
{
    CGMutablePathRef path = CGPathCreateMutable();
    CGPathMoveToPoint(path, NULL,CGRectGetMinX(rect), CGRectGetMinY(rect)+radius);
    CGPathAddArcToPoint(path,NULL,CGRectGetMinX(rect),CGRectGetMinY(rect), CGRectGetMaxX(rect)-radius, CGRectGetMinY(rect),radius);
    CGPathAddArcToPoint(path,NULL,CGRectGetMaxX(rect), CGRectGetMinY(rect),CGRectGetMaxX(rect), CGRectGetMaxY(rect)-radius,radius);
    CGPathAddArcToPoint(path,NULL,CGRectGetMaxX(rect), CGRectGetMaxY(rect),CGRectGetMinX(rect)+radius, CGRectGetMaxY(rect),radius);
    CGPathAddArcToPoint(path,NULL,CGRectGetMinX(rect), CGRectGetMaxY(rect),CGRectGetMinX(rect), CGRectGetMinY(rect)+radius,radius);
    CGPathCloseSubpath(path);
    return path;
}

CGPathRef CGPathCreateFan(CGPoint center, CGFloat radius, CGFloat angle1, CGFloat angle2)
{
    CGMutablePathRef path = CGPathCreateMutable();
    CGPathMoveToPoint(path, NULL, center.x, center.y);
    CGPoint point1 = CGPointMake(center.x+radius*cos(angle1),center.y + radius*sin(angle1));
    CGPathAddLineToPoint(path, NULL, point1.x, point1.y);
    CGPathAddArc(path,NULL,center.x, center.y, radius, angle1, angle2,0);
    CGPathAddLineToPoint(path,NULL,center.x, center.y);	
    CGPathCloseSubpath(path);
    return path;
}
